$(function () {
    if ($(window).width() <= 1170) {
        $("footer").find("li").css("padding", "0 38px");
    }
    // $('#Marquee_x').jcMarquee({'marquee': 'x', 'margin_right': '10px', 'speed': 30});
    // DIVCSS5提示：10px代表间距，第二个20代表滚动速度
    //首页赋值
    var cacheObj = {};

    // 获取首页主数据
    $.ajax({
        url: SERVICE_URL + '/front/home',
        type: 'get',
        contentType: 'application/json',
        dataType: "json",
        success: function (res) {
            if (res.code === 0) {
                $(res.data).each(function (i, item) {
                    switch (item.categoryId) {
                        case 10:
                            $("#c_title1").html(item.categoryName);
                            $("#c_more1").attr("href", "list.html?categoryId=" + item.categoryId);
                            break;
                        case 3:
                            $("#c_title2").html(item.categoryName);
                            $("#c_more2").attr("href", "list.html?categoryId=" + item.categoryId);
                            break;
                        case 4:
                            $("#c_title3").html(item.categoryName);
                            $("#c_more3").attr("href", "list.html?categoryId=" + item.categoryId);
                            break;
                        case 5:
                            $("#c_title4").html(item.categoryName);
                            $("#c_more4").attr("href", "list.html?categoryId=" + item.categoryId);
                            break;
                        case 6:
                            $("#c_title5").html(item.categoryName);
                            $("#c_more5").attr("href", "list.html?categoryId=" + item.categoryId);
                            break;
                        case 8:
                            $("#c_title6").html(item.categoryName);
                            $("#c_more6").attr("href", "list.html?categoryId=" + item.categoryId);
                            break;
                        case 7:
                            $("#c_title7").html(item.categoryName);
                            $("#c_more7").attr("href", "list.html?categoryId=" + item.categoryId);
                            break;
                        case 9:
                            $("#c_title8").html(item.categoryName);
                            $("#c_more8").attr("href", "list.html?categoryId=" + item.categoryId);
                            break;
                        case 11:
                            $("#c_title9").html(item.categoryName);
                            $("#c_more9").attr("href", "list.html?categoryId=" + item.categoryId);
                            break;
                        case 12:
                            $("#c_title10").html(item.categoryName);
                            $("#c_more10").attr("href", "list.html?categoryId=" + item.categoryId);
                            break;
                        case 13:
                            $("#c_title11").html(item.categoryName);
                            $("#c_more11").attr("href", "list.html?categoryId=" + item.categoryId);
                            break;
                        case 14:
                            $("#c_title12").html(item.categoryName);
                            $("#c_more12").attr("href", "list.html?categoryId=" + item.categoryId);
                            break;
                        case 15:
                            $("#c_title13").html(item.categoryName);
                            $("#c_more13").attr("href", "list.html?categoryId=" + item.categoryId);
                            break;
                        case 16:
                            $("#c_title14").html(item.categoryName);
                            $("#c_more14").attr("href", "list.html?categoryId=" + item.categoryId);
                            break;
                        case 17:
                            $("#c_title15").html(item.categoryName);
                            cacheObj.c_list15 = item;
                            break;
                        case 18:
                            $("#c_title16").html(item.categoryName);
                            cacheObj.c_list16 = item;
                            var str = '';
                            $(cacheObj.c_list16.list).each(function (j, article) {
                                str = str + '<li class="img-list"><a href="article.html?articleId=' + article.articleId + '&categoryId=' + cacheObj.c_list16.categoryId + '"><img src="' + SERVICE_URL + article.imageUrl + '" alt=""><p class="text-center">' + article.title + '</p></a></li>';
                            });
                            $("#c_list").html(str);
                            $("#c_more").attr("href", "list.html?categoryId=" + cacheObj.c_list16.categoryId);
                            break;
                        case 2:
                            $("#c_title17").html(item.categoryName);
                            cacheObj.c_list17 = item;
                            break;
                        case 19:
                            $("#c_title18").html(item.categoryName);
                            cacheObj.c_list18 = item;
                            break;
                        case 32:
                            $(".other1").html(item.list[2].title);
                            $(".other1").attr('href',"article.html?categoryId=32&articleId="+item.list[2].articleId);
                            $(".other2").html(item.list[1].title);
                            $(".other2").attr('href',"article.html?categoryId=32&articleId="+item.list[1].articleId);
                            $(".other3").html(item.list[0].title);
                            $(".other3").attr('href',"article.html?categoryId=32&articleId="+item.list[0].articleId);
                            $(".other4").html(item.list[3].title);
                            $(".other4").attr('href',"article.html?categoryId=32&articleId="+item.list[3].articleId);
                            break;
                        default:
                            break;
                    }
                    $(".page").removeClass("hidden");
                    $(".loading").addClass("hidden");
                });
            } else {

            }
        },
        error: function () {

        }
    });

    // 获取联系信息数据
    $.ajax({
        url: SERVICE_URL + '/front/contact',
        type: 'get',
        contentType: 'application/json',
        dataType: "json",
        success: function (res) {
            if (res.code === 0) {
                $("#phone").text('联系电话：' + res.data.phone);
                $("#mail").text('邮箱：' + res.data.mail);
                $("#address").text('地址：' + res.data.address);
                $("#qrcode").attr('src', res.data.qrcode);
                $("#fax").text('传真：' + res.data.fax);
                $("#supportHotline").text('咨询电话：' +  res.data.supportHotline);
            }
        },
        error: function () {

        }
    });

    // 获取友情链接信息
    $.ajax({
        url: SERVICE_URL + '/front/links',
        type: 'get',
        contentType: 'application/json',
        dataType: "json",
        success: function (res) {

            if (res.code === 0) {
                var str = '';
                $(res.data).each(function () {
                    str = str + '<li><a href="' + this.address + '">/' + this.name + '</a></li>';
                });
                $("#friendship_links").html(str);
            }
        },
        error: function () {

        }
    });

    // 获取地图信息
    $.ajax({
        url: SERVICE_URL + '/manage/map/list',
        type: 'get',
        contentType: 'application/json',
        dataType: "json",
        success: function (res) {
            $(".area-remark-1").find("button").attr("data-content", res.data[0].content);
            $(".area-remark-3").find("button").attr("data-content", res.data[1].content);
            $(".area-remark-2").find("button").attr("data-content", res.data[2].content);
            $(".area-remark-4").find("button").attr("data-content", res.data[3].content);
            $(".position-remark-1").find("button").attr("data-content", res.data[4].content);
            $(".position-remark-2").find("button").attr("data-content", res.data[5].content);
            $(".position-remark-4").find("button").attr("data-content", res.data[6].content);
            $(".position-remark-3").find("button").attr("data-content", res.data[7].content);
            $(".position-remark-5").find("button").attr("data-content", res.data[8].content);
            $(".position-remark-6").find("button").attr("data-content", res.data[9].content);
            $(".position-remark-7").find("button").attr("data-content", res.data[10].content);
            $(".position-remark-9").find("button").attr("data-content", res.data[11].content);
            $(".position-remark-8").find("button").attr("data-content", res.data[12].content);
        },
        error: function () {

        }
    });

    // 监听公共资源及基础信息tap栏
    $("#common_environment_list").find("li").click(function () {
        $(this).addClass("zs-active");
        $(this).siblings().removeClass("zs-active");
        if ($(this).attr("id") == "c_title15") {
            var str = '';
            $(cacheObj.c_list15.list).each(function (j, article) {
                if (j <= 4) {
                    str = str + '<li class="img-list"><a href="article.html?articleId=' + article.articleId + '&categoryId=' + cacheObj.c_list15.categoryId + '"><img src="' + SERVICE_URL + article.imageUrl + '" alt=""><p class="text-center">' + article.title + '</p></a></li>';
                }
            });
            $("#c_list").html(str);
            $("#c_more").attr("href", "list.html?categoryId=" + cacheObj.c_list15.categoryId);
        } else if ($(this).attr("id") == "c_title16") {
            var str = '';
            $(cacheObj.c_list16.list).each(function (j, article) {
                if (j <= 4) {
                    str = str + '<li class="img-list"><a href="article.html?articleId=' + article.articleId + '&categoryId=' + cacheObj.c_list16.categoryId + '"><img src="' + SERVICE_URL + article.imageUrl + '" alt=""><p class="text-center">' + article.title + '</p></a></li>';
                }
            });
            $("#c_list").html(str);
            $("#c_more").attr("href", "list.html?categoryId=" + cacheObj.c_list16.categoryId);
        } else if ($(this).attr("id") == "c_title17") {
            var str = '';
            $(cacheObj.c_list17.list).each(function (j, article) {
                if (j <= 4) {
                    str = str + '<li class="img-list"><a href="article.html?articleId=' + article.articleId + '&categoryId=' + cacheObj.c_list17.categoryId + '"><img src="' + SERVICE_URL + article.imageUrl + '" alt=""><p class="text-center">' + article.title + '</p></a></li>';
                }
            });
            $("#c_list").html(str);
            $("#c_more").attr("href", "list.html?categoryId=" + cacheObj.c_list17.categoryId);
        } else if ($(this).attr("id") == "c_title18") {
            var str = '';
            $(cacheObj.c_list18.list).each(function (j, article) {
                if (j <= 4) {
                    str = str + '<li class="img-list"><a href="article.html?articleId=' + article.articleId + '&categoryId=' + cacheObj.c_list18.categoryId + '"><img src="' + SERVICE_URL + article.imageUrl + '" alt=""><p class="text-center">' + article.title + '</p></a></li>';
                }
            });
            $("#c_list").html(str);
            $("#c_more").attr("href", "list.html?categoryId=" + cacheObj.c_list18.categoryId);
        }
    });

    // 监听乡镇概况tap栏
    $("#town_info").find("li").click(function () {
        $(this).addClass("zs-active");
        $(this).siblings().removeClass("zs-active");
        if ($(this).attr("id") == "c_title25") {
            var str = '';
            $(cacheObj.c_list7.list).each(function (j, article) {
                str = str + '<li><a href="article.html?articleId=' + article.articleId + '"><img src="' + SERVICE_URL + article.imageUrl + '" alt=""><p class="text-center">' + article.title + '</p></a></li>';
            });
            $("#c_list7").html(str);
            $("#c_more25").attr("href", "list.html?categoryId=" + cacheObj.c_list7.categoryId);
        } else if ($(this).attr("id") == "c_title26") {
            var str = '';
            $(cacheObj.c_list26.list).each(function (j, article) {
                str = str + '<li><a href="article.html?articleId=' + article.articleId + '"><img src="' + SERVICE_URL + article.imageUrl + '" alt=""><p class="text-center">' + article.title + '</p></a></li>';
            });
            $("#c_list6").html(str);
            $("#c_more26").attr("href", "list.html?categoryId=" + cacheObj.c_list26.categoryId);
        } else if ($(this).attr("id") == "c_title27") {
            var str = '';
            $(cacheObj.c_list27.list).each(function (j, article) {
                str = str + '<li><a href="article.html?articleId=' + article.articleId + '"><img src="' + SERVICE_URL + article.imageUrl + '" alt=""><p class="text-center">' + article.title + '</p></a></li>';
            });
            $("#c_list6").html(str);
            $("#c_more25").attr("href", "list.html?categoryId=" + cacheObj.c_list27.categoryId);
        } else if ($(this).attr("id") == "c_title28") {
            var str = '';
            $(cacheObj.c_list28.list).each(function (j, article) {
                str = str + '<li><a href="article.html?articleId=' + article.articleId + '"><img src="' + SERVICE_URL + article.imageUrl + '" alt=""><p class="text-center">' + article.title + '</p></a></li>';
            });
            $("#c_list6").html(str);
            $("#c_more25").attr("href", "list.html?categoryId=" + cacheObj.c_list28.categoryId);
        } else if ($(this).attr("id") == "c_title29") {
            var str = '';
            $(cacheObj.c_list29.list).each(function (j, article) {
                str = str + '<li><a href="article.html?articleId=' + article.articleId + '"><img src="' + SERVICE_URL + article.imageUrl + '" alt=""><p class="text-center">' + article.title + '</p></a></li>';
            });
            $("#c_list6").html(str);
            $("#c_more25").attr("href", "list.html?categoryId=" + cacheObj.c_list29.categoryId);
        }
    });

    // 监听搜索
    $("#search_btn").click(function () {
        var searchInfo = $("#search_info").val();
        window.location.href = ('./list.html?search=' + searchInfo);
    });

    // 监听点击更多友情链接
    $(".more-links").click(function () {
        var friendLink = $(".friend-link");
        friendLink.css("overflow","unset");
        $(".more-links-box").hide();

    });
});